<!DOCTYPE html>
<html>

@include('public/header')

<body class="gray-bg">
<div class="row">
    <div class="col-sm-12">
        <div class="wrapper wrapper-content animated fadeInUp">

            <div class="ibox-content m-b-sm border-bottom">

                <div class="btn-group" style="float: left">
                    <select class="form-control" name="type" onchange="searchKnowledge()">
                        @foreach($brief as $k => $v)

                        <option value="{{$v['id']}}"
                        @if($type == $v['id']) selected
                        @endif
                        >{{$v['name']}}</option>

                        @endforeach
                    </select>
                </div>

                <div class="row">
                    <div class="col-lg-4">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="Search for..." name="keyword" value="{{$keyword}}">
                            <span class="input-group-btn">
                                <button id="search" class="btn btn-primary" type="button" onclick="searchKnowledge()">搜索!</button>
                            </span>
                        </div><!-- /input-group -->
                    </div><!-- /.col-lg-6 -->
                </div>

            </div>

            <div id="content">
                @foreach($list as $k=>$v)
                    <div class="faq-item">
                        <div class="row">
                            <div class="col-md-7">
                                <a  href="{{url('admin/knowledge/detail')}}?id={{$v['id']}}&type={{$type}}&keyword={{$keyword}}" class="faq-question">{!! $v['desc'] !!}</a>
                                <small><strong>{{$v['admin_name']}}</strong> <i class="fa fa-clock-o"></i> {{$v['updated_at']}}</small>
                            </div>
                            <div class="col-md-3">
                                <span class="small font-bold">{{$v['type_name']}}</span>
                                <div class="tag-list">
                                    @if($v['picture'])
                                        @foreach($v['picture'] as $i => $j)
                                            <img src="{{$j}}" alt="" style="width:20px;">
                                        @endforeach
                                    @endif
                                </div>
                            </div>
                            <div class="col-md-2 text-right">
                                <span class="small font-bold">浏览次数 </span>
                                <br/>
                                <h4 style="color: #1e7e34">{{$v['click']}}</h4>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <div id="faq2" class="panel-collapse collapse faq-answer">
                                    <p>
                                        <br>原因：{{$v['reason']}}
                                        <br>处理办法：{{$v['method']}}
                                        <br>备注：{{$v['content']}}
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>

        </div>
    </div>
</div>

@include('public/footer')

<script>
    $(document).ready(function () {

        $('#loading-example-btn').click(function () {
            btn = $(this);
            simpleLoad(btn, true)

            // Ajax example
            //                $.ajax().always(function () {
            //                    simpleLoad($(this), false)
            //                });

            simpleLoad(btn, false)
        });
    });

    function simpleLoad(btn, state) {
        if (state) {
            btn.children().addClass('fa-spin');
            btn.contents().last().replaceWith(" Loading");
        } else {
            setTimeout(function () {
                btn.children().removeClass('fa-spin');
                btn.contents().last().replaceWith(" Refresh");
            }, 2000);
        }
    }
</script>

<script>
    function searchKnowledge(){
        let type = $("select[name='type']").val();
        let keyword = $("input[name='keyword']").val();
        // $("#search").attr('class', 'btn btn-default');
        // $("#search").removeClass('btn btn-primary');

        $.ajax({
            url: "{{url('/admin/knowledge/content')}}",
            data:{type: type, keyword:keyword},
            type:"post",
            success: function (res) {
                $("#content").html(res);
            },
            error: function (error) {
                console.log(error)
            }
        });
    }
</script>

</body>

</html>
